package annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class clazz = Class.forName("annotation.Parent");
        Method[] methods = clazz.getMethods();
        if (methods!=null){
            for (Method method:methods){
                boolean isInitMethod = method.isAnnotationPresent(InitMethod.class);
                System.out.println(method.getName()+":"+isInitMethod);

                //这样在加载类的时候就可以初始化执行
                if (isInitMethod){
                    method.invoke(clazz.getConstructor(null).newInstance(null),null);
                }
            }
        }
    }
}
